package org.cying.main.service;

import cn.hutool.core.date.DateUtil;
import org.cying.main.dao.CreateStudent;
import org.cying.main.dao.DeleteStudent;
import org.cying.main.dao.QueryStudent;
import org.cying.main.dao.UpdateStudent;
import org.cying.main.domain.Student;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学生映射接口控制类
 * @author Cying
 */
@Service
public class StudentService {
    
    @Resource
    private QueryStudent query;
    
    @Resource
    private CreateStudent create;
    
    @Resource
    private UpdateStudent update;

    @Resource
    private DeleteStudent delete;
    
    public List<Student> getStuBySid(Long sid, String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("name", name);
        return query.getStuBySid(map);
    }
    
    public List<Student> getStuByDept(String dept, String group) {
        Map<String, Object> map = new HashMap<>();
        map.put("dept", dept);
        map.put("group", group);
        return query.getStuByDept(map);
    }
    
    public List<Student> getDutyList(String time) {
        Map<String, Object> map = new HashMap<>();
        map.put("time", time);
        map.put("today", DateUtil.today());
        return query.getDutyList(map);
    }
    
    public Student authPasswd(Long sid, String password) {
        Map<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("password", password);
        return query.authPasswd(map);
    }
    
    public boolean insertStudent(Long sid, String name, String college, String dept, String group) {
        Map<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("name", name);
        map.put("college", college);
        map.put("dept", dept);
        map.put("group", group);
        return create.insertStudent(map) == 1;
    }
    
    public int updateLastSign(Long sid) {
        Map<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("today", DateUtil.today());
        return update.updateLastSign(map);
    }
    
    public int updateInfo(Integer type, Object value, Long sid) {
        Map<String, Object> map = new HashMap<>();
        map.put("type", type);
        map.put("v", value);
        map.put("sid", sid);
        return update.updateInfo(map);
    }

    public boolean deleteStudent(Long sid, String department, String group) {
        Map<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("department", department);
        map.put("group", group);
        return delete.deleteStudent(map) > 0;
    }

}
